package com.MarkToTop.main;

import com.MarkToTop.util.Constant;
import com.MarkToTop.util.GameUtil;

import java.awt.*;
import java.awt.image.BufferedImage;


/**
 * MarkWang 版权所有 © Copyright 2020
 *
 * @CreateDate: Created in 2020-06-22 12:16
 * @Author: MarkToTop -(づ｡◕‿‿◕｡)づ
 * @Description:
 */
public class GameBackGround {

    //需要的背景资源
    private BufferedImage BGImg;

    //构造方法,对资源进行初始化
    public GameBackGround() {
        BGImg = GameUtil.loadBufferedImage(Constant.BG_IMG_PATH);
    }

    //绘制方法
    public void draw(Graphics g){

        //先绘制背景色
        g.setColor(Constant.BG_Color);
        g.fillRect(0,0,Constant.Frame_Width,Constant.Frame_Height);

        //得到图片数据
        int IMG_Width = BGImg.getWidth();
        int IMG_Height = BGImg.getHeight();

        /**
         * 根据次数，循环绘制
         */
        //次数
        int count = Constant.Frame_Width/IMG_Width + 1;
        //用画笔在指定位置进行绘制
        for (int i = 0; i < count; i++) {

            g.drawImage(BGImg,IMG_Width * i,Constant.Frame_Height-IMG_Height,null);

        }
    }
}
